package com.TPNexus.dao;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Set;

import org.hibernate.Session;
import org.junit.Test;

import com.TPNexus.model.CatalogItem;
import com.TPNexus.model.ShoppingCart;
import com.TPNexus.model.ShoppingCartItem;

public class ShoppingCartDAOTest {

	@Test
	public void testGetShoppingCartItemList() {
		ShoppingCartDAO sdao=new ShoppingCartDAO();
		ArrayList<ShoppingCartItem> set=sdao.getShoppingCartItemList(1);
		for (ShoppingCartItem shoppingCartItem : set) {
			System.out.print(shoppingCartItem.getCatalogItem().getProduct().getName()+"+"+shoppingCartItem.getQty());
		}
	}

	
	@Test
	public void testnewShoppingCart() {
		ShoppingCartDAO sdao = new ShoppingCartDAO();
		ShoppingCart sc = new ShoppingCart();
		sc.setUserId(3);
		sdao.creatNewShoppingCart(sc);
	}
	
	@Test
	public void testaddToShoppingCart() {
		ShoppingCartDAO sdao = new ShoppingCartDAO();
		ShoppingCart sc = new ShoppingCart();
		ShoppingCartItem sci=new ShoppingCartItem();
		CatalogItem catalogItem=new CatalogItem();
		Session session = HibernateUtil.getSessionFactory().openSession();
		session.beginTransaction();
		sc=(ShoppingCart) session.get(ShoppingCart.class, (long)3);
		catalogItem=(CatalogItem) session.get(CatalogItem.class, (long)9);
		session.getTransaction().commit();
		sci.setCatalogItem(catalogItem);
		sci.setQty(25);
		sdao.addToShoppingCart(sci, sc);
	}
	
}
